<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!--css-->
<link type="text/css"
	href="<%=basePath%>static/bootstrap/css/bootstrap.css" rel="stylesheet" />
<!--bootstrap-responsive-->
<link type="text/css"
	href="<%=basePath%>static/bootstrap/css/bootstrap-responsive.css"
	rel="stylesheet" />
<link type="text/css"
	href="<%=basePath%>static/jquery-loadmask-0.4/jquery.loadmask.css"
	rel="stylesheet" />
<!--bootstrap-->
<script type="text/javascript" src="<%=basePath%>static/js/jquery.js"></script>
<script type="text/javascript" src="<%=basePath%>static/jquery-loadmask-0.4/jquery.loadmask.min.js"></script>
<script type="text/javascript"
	src="<%=basePath%>static/bootstrap/js/bootstrap.js"></script>
<script language="javascript" type="text/javascript"
	src="<%=basePath%>static/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
    var basePath = '<%=basePath%>';

    function mask(){
    	$('#view').mask("加载中...");
    }
    
    function unMask(){
    	$('#view').unmask();
    }
    function go(url){
		mask();
    	$('#view').load(basePath+url,function(){
        	unmask();
        });
    }
    function tb_check(){
        if($('#ids').attr("checked")=="checked"){
            $('input[type="checkbox"]').attr("checked",'true');//全选
        }else{
            $('input[type="checkbox"]').removeAttr('checked');
        }
    }
    
    function edit(url){
        var ids = $('input[name="ids"]:checked');
        if(ids.size()>1){
            alert('编辑一个');
        }else if(ids.size()==1){
            go(url+'&ids='+ids.val());
        }
    }
    
    function view(url){
        var ids = $('input[name="ids"]:checked');
        if(ids.size()>1){
            alert('查看一个');
        }else if(ids.size()==1){
            go(url+'&ids='+ids.val());
        }
    }
    
    
    function del(url){
        var ids = $('input[name="ids"]:checked');
        if(ids.size()>0){
            var str = "";
            ids.each(function(){
                str +=$(this).val()+",";
            });
            str = str.substring(0,str.length-1);
            go(url+'&ids='+str);
        }
    }
    
    function goView(url){
    	$('#view').load(basePath+url);
    }
    
    function goShow(){
    	$('#view').load(basePath+"view/show.jsp");
    }
    
    function goMenu(){
    	$('#view').load(basePath+'view/myjsp.jsp');
    }
    
    function goFile(){
    	$('#view').load(basePath+'view/myfile.jsp');
    }
    function goStore(){
    	$('#view').load(basePath+'storem/store?list');
    }
    
    function tologin(){
    	window.location.href=basePath;
    }
    
    function close_page(){
    	self.opener=null;
    	self.open('', '_self');
    	self.close();
    }
    
    
    /*分页  */
    function first_page() {
		$('input[name="pageNum"]').val(1);
		var url = $('#form').attr("action");
		go(url + '&' + $('#form').serialize());
	}

	function last_page() {
		$('input[name="pageNum"]').val($('input[name="totalPage"]').val());
		var url = $('#form').attr("action");
		go(url + '&' + $('#form').serialize());
	}

	function first_Dpage() {
		$('input[name="pageNum"]').val(1);
		var url = $('#dialogForm').attr("action");
		model_show(url + '&' + $('#dialogForm').serialize());
	}

	function last_Dpage() {
		$('input[name="pageNum"]').val($('input[name="totalPage"]').val());
		var url = $('#dialogForm').attr("action");
		model_show(url + '&' + $('#dialogForm').serialize());
	}
    
	
	function form_submit(url){
	        $('#form').submit(function(){
	            jQuery.ajax({
	                url:'<%=basePath%>'+url,
	                data:$('#form').serialize(),
	                target:'main',
	                type:'post',
	                beforeSend:function(){
	                    //new screenClass().lock();
	                },
	                success:function(url){
	                    //new screenClass().unlock();
	                    go(url);
	                },
	                error: function(XMLHttpRequest, textStatus, errorThrown) {
	                    alert(XMLHttpRequest.status);
	                    alert(XMLHttpRequest.readyState);
	                    alert(textStatus);
	                }
	            });
	            return false;
	        });
	    }
	
	function fileForm_submit(url){
        $('#form').submit(function(){
            jQuery.ajax({
                url:'<%=basePath%>'+url,
                data:$('#form').serialize(),
                target:'main',
                type:'post',
                fileElementId:'file',
                beforeSend:function(){
                    //new screenClass().lock();
                },
                success:function(url){
                    //new screenClass().unlock();
                    go(url);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.readyState);
                    alert(textStatus);
                }
            });
            return false;
        });
    }
	    
	    function goPage(num){
	        $('input[name="pageNum"]').val(num);
	        var url = $('#form').attr("action");
	        go(url+'&'+$('#form').serialize());
	    }
	    
	    function goDialog(num){
	    	$('input[name="pageNum"]').val(num);
	        var url = $('#dialogForm').attr("action");
	        model_show(url+'&'+$('#dialogForm').serialize());
	        //go(url+'&'+$('#dialogForm').serialize());
	    }
	    function model_show(url){
	    	$('#myModal').modal('show');
	    	$('#model_body').load('<%=basePath%>' + url);
	}

	var id ;
	var text;
	    
	function menu_search() {
		model_show('system/menu?query');
		id = $('input[name="father.id"]');
		text = $('input[name="father.name"]');
	}

	function role_search() {
		model_show('system/role?query');
		id = $('input[name="role_id"]');
		text = $('input[name="role_name"]');
	}

	function returnValue() {
		var ids = $('input[name="ids"]:checked');
		if(ids.size()>0){
            var idS = "";
            var textS = "";
            ids.each(function(){
            	var data = $(this).val().split(",");
				idS += data[0]+ ",";
				textS += data[1]+ ",";
            });
            idS = idS.length>0?idS.substring(0,idS.length-1):"";
            textS = textS.length>0?textS.substring(0,textS.length-1):"";
            
    		id.val(idS);
    		text.val(textS);
        }else{
        	var data = ids.val().split(",");
    		id.val(data[0]);
    		text.val(data[1]);
        }
		$('#myModal').modal('hide');
	}
</script>

